package com.xhd.config;

import java.io.File;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import com.xhd.action.Action;
import com.xhd.base.log.Log;
import com.xhd.base.log.LogFactory;
import com.xhd.exception.SystemException;
import com.xhd.exception.XException;
import com.xhd.server.ServerConfig;
import com.xhd.xml.XMLSerializer;

public class ActionConfig {
	 private static final Log jm9;
	  private String jm21;
	  private boolean jm22;
	  private boolean jm23;
	  private static HashMap jm24;
	  static Class jm10;

	  static
	  {
	    Class tmp3_0 = jm10;
	    if (tmp3_0 == null)
	    {
	    
	      try
	      {
	         ActionConfig.jm10 = Class.forName("com.sinocc.base.config.ActionConfig");
	      }
	      catch (ClassNotFoundException localClassNotFoundException)
	      {
	        throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
	      }
	    }
	    jm9 = LogFactory.getLog(tmp3_0);
	    jm24 = null;
	  }

	  private boolean jm11()
	    throws XException
	  {
	    try
	    {
	      XMLSerializer localXMLSerializer = null;
	      String str1 = ServerConfig.getConfFilePath("action");
	      File localFile = new File(str1);
	      if ((!(localFile.exists())) && (!(localFile.isFile())))
	        return false;
	      FileInputStream localFileInputStream = new FileInputStream(localFile);
	      localXMLSerializer = new XMLSerializer(localFileInputStream, false);
	      Vector localVector = localXMLSerializer.getCollection("action-config");
	      localFileInputStream.close();
	      if ((localVector == null) || (localVector.size() < 1))
	        return false;
	      int i = localVector.size();
	      jm24 = new HashMap(i);
	      for (int j = 0; j < i; ++j)
	      {
	        Map localMap = (Map)localVector.get(j);
	        String str2 = (String)localMap.get("action");
	        if ((str2 == null) || (str2.length() < 1))
	        {
	          jm9.error("Invalid action config: " + j);
	        }
	        else
	        {
	          str2 = str2.toLowerCase();
	          if (jm24.containsKey(str2))
	          {
	            jm9.error("Action config: " + str2 + " repeat!");
	          }
	          else
	          {
	            ActionConfig localActionConfig = new ActionConfig();
	            localActionConfig.jm23 = jm20((String)localMap.get("dbtran"), true);
	            localActionConfig.jm22 = jm20((String)localMap.get("log"), false);
	            localActionConfig.jm21 = ((String)localMap.get("name"));
	            jm24.put(str2, localActionConfig);
	          }
	        }
	      }
	      jm9.info("Action config size: " + jm24.size());
	      return true;
	    }
	    catch (Exception localException)
	    {
	      jm9.error(localException);
	      throw new SystemException(10028, localException.getMessage());
	    }
	  }

	  private boolean jm20(String paramString, boolean paramBoolean)
	  {
	    if (paramString == null)
	      return paramBoolean;
	    return (("2".equals(paramString)) || ("true".equalsIgnoreCase(paramString)));
	  }

	  public static synchronized ActionConfig getConfig(Action paramAction)
	    throws XException
	  {
	    if (jm24 == null)
	    {
	     ActionConfig localObject = new ActionConfig();
	      if (!(((ActionConfig)localObject).jm11()))
	      {
	        jm24 = new HashMap();
	        jm9.error("Warning: not action config!");
	      }
	    }
	    Object localObject = paramAction.getMethodName();
	    ActionConfig localActionConfig = (ActionConfig)jm24.get(localObject);
	    if (localActionConfig == null)
	    {
	      jm9.error("Warning: action " + ((String)localObject) + " not config!");
	      localActionConfig = new ActionConfig();
	      localActionConfig.jm23 = true;
	      localActionConfig.jm22 = true;
	      localActionConfig.jm21 = ((String)localObject);
	      jm24.put(localObject, localActionConfig);
	    }
	    return ((ActionConfig)localActionConfig);
	  }

	  public String getName()
	  {
	    return this.jm21;
	  }

	  public boolean isLog()
	  {
	    return this.jm22;
	  }

	  public boolean isDBTran()
	  {
	    return this.jm23;
	  }
}
